package com.xy.blog.core.springmvc.controller;

import com.xy.blog.core.exception.BaseException;
import com.xy.blog.core.springmvc.result.page.PageReq;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author zanhonglei
 * @version V1.0
 * @Description: controller 基础 CURD
 * @date 2020/3/5
 */

public interface IBaseController<QUERY, REQ> {

    /**
     * 分页查询
     *
     * @param req
     * @return
     * @throws BaseException
     */
    @PostMapping("/pages")
    @ApiOperation(value = "分页查询", notes = "分页查询", httpMethod = "POST")
    default Object pages(@RequestBody PageReq<QUERY> req) throws BaseException {
        return null;
    }

    /**
     * 根据id获取一个
     *
     * @param id
     * @return
     * @throws BaseException
     */
    @GetMapping()
    @ApiOperation(value = "根据id获取一个", notes = "根据id获取一个", httpMethod = "GET")
    default Object getById(@RequestParam Long id) throws BaseException {
        return null;
    }

    /**
     * 新增
     *
     * @param req
     * @return
     * @throws BaseException
     */
    @PostMapping()
    @ApiOperation(value = "新增", notes = "新增", httpMethod = "POST")
    default Object save(@Valid @RequestBody REQ req) throws BaseException {
        return null;
    }

    /**
     * 更新
     *
     * @param req
     * @return
     * @throws BaseException
     */
    @PutMapping()
    @ApiOperation(value = "更新", notes = "更新", httpMethod = "PUT")
    default Object update(@Valid @RequestBody REQ req) throws BaseException {
        return null;
    }

    /**
     * 根据id删除
     *
     * @param id
     * @return
     * @throws BaseException
     */
    @DeleteMapping()
    @ApiOperation(value = "根据id删除用户", notes = "根据id删除用户", httpMethod = "DELETE")
    default Object deleteById(@RequestParam Long id) throws BaseException {
        return null;
    }
}
